<?php

namespace api\wxapp\model;

use think\Model;
use api\wxapp\model\ShopGoods;
use api\wxapp\model\Comment;
use api\wxapp\model\ScoreGoods;
class Goods extends Model
{
    protected $table = 'sssc_goods';

    public function getList($where)
    {
        return ShopGoods::alias('t1')
        ->join('goods t2','t2.id = t1.goods_id')
        ->field('t1.price,t2.name,t2.id,t2.img,t2.para1,t2.sales')
        ->where($where)
        ->select();
    }

    public function info($data)
    {
        $info = self::get($data['goods_id']);
        $arr['id'] = $info['id'];
        $arr['name'] = $info['name'];
        $arr['img'] = $info['img'];
        $arr['price'] = $info['price'];
        $arr['old_price'] = $info['old_price'];
        $arr['sales'] = $info['sales'];
        $arr['content'] = $info['content'];
        $find = ShopGoods::where(array('goods_id'=>$data['goods_id'],'shop_id'=>$data['shop_id']))->find();
        if($find){
            //是店铺商品    看是否是秒杀商品
            $arr['price'] = $find['price'];
            $arr['score'] = $find['score'];
        }
        $arr['comment'] = Comment::where('goods_id',$data['goods_id'])->count();
        return $arr;
    }

    //获取积分商城商品
    public function getScoreList($where)
    {
        return ScoreGoods::alias('t1')
        ->join('goods t2','t2.id = t1.goods_id')
        ->field('t1.price,t2.name,t2.id,t1.score,t2.img,t2.para1')
        ->where($where)
        ->select();
    }
}
